﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DA_OOMModel;
using System.Web.Security;
using DA_OOMModelIDAL;
using DA_OOMDALFactory;

namespace DaCredito.Account
{
    public partial class Login : WebPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            string lsUsername = LoginUser.UserName;
            string lsPassword = LoginUser.Password;

            Usuario loUsuario = ControladorContaUsuario.GetInstance().AutenticarUsuario(lsUsername, lsPassword);
            if (loUsuario == null)
            {
                this.DisparaMensagem("Usuário ou senha inválidos.", TipoOperacao.Failure);
                return;
            }


            IClienteDAL loCidadeDAO = ConcreteDALFactory.CreateClienteDAL();

           // List<Cliente> loListaCliente = loCidadeDAO.FindByUsuario(loUsuario);


            Session["Usuario"] = loUsuario;

            FormsAuthentication.RedirectFromLoginPage(lsUsername, LoginUser.RememberMeSet);


        }
        /// <summary>
        /// Fires when Login button will be clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {/*
            bool authenticated = AuthenticateMe(Login1.UserName, Login1.Password, Login1.RememberMeSet);
            if (authenticated)
            {
                FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);
            }*/
        }
    }
}
